<?php
//douban api
/*
//json
$info_json = file_get_contents('http://api.douban.com/movie/subject/'.$douban_id.'?apikey=08602de67c55be86192089b375013b92&alt=json');
$info_obj = json_decode($info_json);
print_r($info_obj);
*/
/*
//xml
$xml = simplexml_load_file('http://api.douban.com/movie/subject/'.$douban_id.'?apikey=08602de67c55be86192089b375013b92');

echo $xml->getName() . "<br />";

foreach($xml->children() as $child)
  {
  echo $child->getName() . ": " . $child . "<br />";
  }
*/

//$a = file_get_contents('http://api.douban.com/movie/subject/'.$douban_id.'?apikey=08602de67c55be86192089b375013b92');
$file = fopen('http://api.douban.com/movie/subject/'.$douban_id.'?apikey=08602de67c55be86192089b375013b92',"r");

$douban_array = array(
'imdb_url' => '<db:attribute name="imdb">',
'name' => '<db:attribute lang="zh_CN" name="aka">',
'copyright_began_time' => '<db:attribute name="pubdate">',
'cast' => '<db:attribute name="cast">',
'screenwriter' => '<db:attribute name="writer">',
'director' => '<db:attribute name="director">',
);

while(! feof($file))
  {
  	$one_line = fgets($file);
  	if(stripos($one_line,'<title>'))
  	{
  		$film_info['name'] = trim(strip_tags($one_line));
  	}
  	if(stripos($one_line,'</db:attribute>'))
  	{
  		$one_line = str_replace('</db:attribute>','',$one_line);
	  	foreach($douban_array as $key=>$value)
	  	{
			if(stripos($one_line,$value))
			{
				$d = str_replace($value,'',$one_line);
				if(isset($film_info[$key])&&!empty($film_info[$key]))
				{
					$film_info[$key] .= ' / '.trim($d);
				}
				else
				{
					$film_info[$key] = trim($d);
				}
				break;
			}
	  	}
	 }
  }

fclose($file);
$film_info['imdb_id'] = str_replace(array('http://www.imdb.com/title/','/'),array('',''),$film_info['imdb_url']);
if(isset($film_info['name']))
{
	$film_info['film_name']['zh-Hans-CN'] = $film_info['name'];
}

/*
//抓站
$a = file_get_contents('http://movie.douban.com/subject/'.$douban_id.'/');

$start = stripos($a,'<div id="info">');
$end = stripos($a,'<div id="interest_sectl">');
$get_info = substr($a,$start,$end-$start);
$b = strip_tags($get_info);

$start = stripos($a,'<h1>');
$end = stripos($a,'</h1>');
$name = substr($a,$start,$end-$start);
$film_info['film_name']['zh-Hans-CN'] = trim(strip_tags($name));


$douban_array = array(
'imdb_id' => 'imdb链接:',
'false_another_name' => '又名:',
'false_audio_language' => '语言:',
'copyright_began_time' => '上映日期:',
'false_site' => '官方网站:',
'false_country_id' => '制片国家/地区:',
'cast' => '主演:',
'screenwriter' => '编剧:',
'director' => '导演:',
);
$e = $b;
foreach($douban_array as $key=>$value)
{
	$c = stripos($e,$value);
	if($c!==false)
	{
		$d = substr($e,$c);
		$f = substr($e,$c+strlen($value));
		$e = trim(str_replace($d,'',$e));
		$film_info[$key] = trim($f);
	}
}
*/
?>
